namespace SilverSea.Untilities
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Drawing.Printing;
    using System.Windows.Forms;

    public static class PrintLPRInfo
    {
        public static List<string> CellValues = new List<string>();
        public static List<string> ColumnHeaders = new List<string>();
        public static string DepartmentManagement = "PH\x00d2NG CSGT ĐƯỜNG BỘ - CA TỈNH KI\x00caN GIANG";
        private static Font font_0 = new Font(new Font("Arial", 18f), FontStyle.Bold);
        private static Font font_1 = new Font(new Font("Arial", 10f), FontStyle.Regular);
        private static Font font_2 = new Font(new Font("Arial", 10f), FontStyle.Bold);
        public static bool IsLandscape = false;
        public static string LocationDetails = "926 Nguyễn Trung Trực";
        public static string LocationTitle = "ĐỊA ĐIỂM: ";
        public static int marginsBottom = 50;
        public static int marginsLeft = 160;
        public static int marginsRight = 160;
        public static int marginsTop = 50;
        public static Image PanoramaImage = null;
        public static string PersonManegementDetails = "L\x00ea Hồng Th\x00e1i";
        public static string PersonManegementTitle = "C\x00c1N BỘ KHAI TH\x00c1C: ";
        private static PrintDocument printDocument_0 = new PrintDocument();
        public static string PrintTitle = "BẢN GHI VI PHẠM GIAO TH\x00d4NG";
        private static StringFormat stringFormat_0;
        private static StringFormat stringFormat_1;
        public static Image VehicleImage = null;
        public static string ViolationDescriptionDetails = "Chạy qu\x00e1 tốc độ cho ph\x00e9p";
        public static string ViolationDescriptionTitle = "LỖI VI PHẠM: ";

        public static void Print(bool showPreview)
        {
            PageSetupDialog dialog = new PageSetupDialog {
                Document = printDocument_0
            };
            dialog.PageSettings.Landscape = IsLandscape;
            dialog.PageSettings.Margins.Top = marginsTop;
            dialog.PageSettings.Margins.Left = marginsLeft;
            dialog.PageSettings.Margins.Right = marginsRight;
            dialog.PageSettings.Margins.Bottom = marginsBottom;
            printDocument_0.BeginPrint += new PrintEventHandler(PrintLPRInfo.smethod_0);
            printDocument_0.PrintPage += new PrintPageEventHandler(PrintLPRInfo.smethod_1);
            if (showPreview)
            {
                PrintPreviewDialog dialog2 = new PrintPreviewDialog {
                    Document = printDocument_0,
                    ShowIcon = false
                };
                dialog2.PrintPreviewControl.Zoom = 0.6;
                dialog2.Width = Screen.PrimaryScreen.Bounds.Width;
                dialog2.Height = Screen.PrimaryScreen.Bounds.Height;
                if (dialog2.ShowDialog() != DialogResult.OK)
                {
                    printDocument_0.BeginPrint -= new PrintEventHandler(PrintLPRInfo.smethod_0);
                    printDocument_0.PrintPage -= new PrintPageEventHandler(PrintLPRInfo.smethod_1);
                    return;
                }
            }
            printDocument_0.Print();
            printDocument_0.BeginPrint -= new PrintEventHandler(PrintLPRInfo.smethod_0);
            printDocument_0.PrintPage -= new PrintPageEventHandler(PrintLPRInfo.smethod_1);
        }

        private static void smethod_0(object sender, PrintEventArgs e)
        {
            stringFormat_0 = new StringFormat();
            stringFormat_0.Trimming = StringTrimming.Word;
            stringFormat_0.FormatFlags = StringFormatFlags.NoWrap;
            stringFormat_0.Alignment = StringAlignment.Center;
            stringFormat_1 = new StringFormat();
            stringFormat_1.Alignment = StringAlignment.Center;
            stringFormat_1.LineAlignment = StringAlignment.Center;
            stringFormat_1.Trimming = StringTrimming.EllipsisCharacter;
        }

        private static void smethod_1(object sender, PrintPageEventArgs e)
        {
            try
            {
                float y = 10f;
                y += e.Graphics.MeasureString(DepartmentManagement, font_1, e.MarginBounds.Width).Height;
                e.Graphics.DrawString(DepartmentManagement, font_1, Brushes.Black, 20f, y);
                y += e.Graphics.MeasureString(PrintTitle, font_0, e.MarginBounds.Width).Height + 10f;
                RectangleF layoutRectangle = new RectangleF((float) e.MarginBounds.Left, y, (float) e.MarginBounds.Width, e.Graphics.MeasureString(PrintTitle, font_0, e.MarginBounds.Width).Height);
                e.Graphics.DrawString(PrintTitle, font_0, Brushes.DarkViolet, layoutRectangle, stringFormat_0);
                y += e.Graphics.MeasureString(ViolationDescriptionTitle, font_1, e.MarginBounds.Width).Height + 30f;
                e.Graphics.DrawString(ViolationDescriptionTitle, font_1, Brushes.Black, (float) e.MarginBounds.Left, y);
                e.Graphics.DrawString(ViolationDescriptionDetails, font_1, Brushes.Black, (float) (e.MarginBounds.Left + 150), y);
                y += e.Graphics.MeasureString(LocationTitle, font_1, e.MarginBounds.Width).Height + 5f;
                e.Graphics.DrawString(LocationTitle, font_1, Brushes.Black, (float) e.MarginBounds.Left, y);
                e.Graphics.DrawString(LocationDetails, font_1, Brushes.Black, (float) (e.MarginBounds.Left + 150), y);
                y += e.Graphics.MeasureString(PersonManegementTitle, font_1, e.MarginBounds.Width).Height + 5f;
                e.Graphics.DrawString(PersonManegementTitle, font_1, Brushes.Black, (float) e.MarginBounds.Left, y);
                e.Graphics.DrawString(PersonManegementDetails, font_1, Brushes.Black, (float) (e.MarginBounds.Left + 150), y);
                if ((ColumnHeaders.Count > 0) && (CellValues.Count > 0))
                {
                    int width = e.MarginBounds.Width / ColumnHeaders.Count;
                    int height = 0x19;
                    int left = e.MarginBounds.Left;
                    int num5 = ((int) y) + 0x19;
                    foreach (string str in ColumnHeaders)
                    {
                        e.Graphics.DrawRectangle(Pens.Black, new Rectangle(left, num5, width, height));
                        e.Graphics.DrawString(str, new Font(font_1, FontStyle.Bold), Brushes.Black, new Rectangle(left, num5, width, height), stringFormat_1);
                        left += width;
                    }
                    num5 += height;
                    left = e.MarginBounds.Left;
                    foreach (string str2 in CellValues)
                    {
                        e.Graphics.DrawRectangle(Pens.Black, new Rectangle(left, num5, width, height));
                        e.Graphics.DrawString(str2, font_1, Brushes.Black, new Rectangle(left, num5, width, height), stringFormat_1);
                        left += width;
                    }
                    y = num5;
                }
                if ((VehicleImage != null) && (PanoramaImage != null))
                {
                    y += e.Graphics.MeasureString("ẢNH XE", font_1, e.MarginBounds.Width).Height + 20f;
                    layoutRectangle = new RectangleF((float) e.MarginBounds.Left, y, (float) e.MarginBounds.Width, e.Graphics.MeasureString("ẢNH XE", font_1, e.MarginBounds.Width).Height);
                    e.Graphics.DrawString("ẢNH XE", font_2, Brushes.DarkGreen, layoutRectangle, stringFormat_0);
                    int num6 = e.MarginBounds.Width - 10;
                    int num7 = (num6 * VehicleImage.Height) / VehicleImage.Width;
                    Rectangle rectangle = new Rectangle(e.MarginBounds.Left + 5, ((int) y) + 20, num6, num7 - 20);
                    e.Graphics.DrawImage(VehicleImage, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                    y += num7;
                    y += e.Graphics.MeasureString("ẢNH TO\x00c0N CẢNH", font_1, e.MarginBounds.Width).Height + 5f;
                    layoutRectangle = new RectangleF((float) e.MarginBounds.Left, y, (float) e.MarginBounds.Width, e.Graphics.MeasureString("ẢNH TO\x00c0N CẢNH", font_1, e.MarginBounds.Width).Height);
                    e.Graphics.DrawString("ẢNH TO\x00c0N CẢNH", font_2, Brushes.DarkGreen, layoutRectangle, stringFormat_0);
                    num7 = (num6 * PanoramaImage.Height) / PanoramaImage.Width;
                    rectangle = new Rectangle(e.MarginBounds.Left + 5, ((int) y) + 20, num6, num7 - 20);
                    e.Graphics.DrawImage(PanoramaImage, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height);
                }
            }
            catch (Exception exception)
            {
                MessageBox.Show("Error while print LPR Info: " + exception.Message);
            }
        }
    }
}

